#include"Dlish.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>

typedef struct node{
    char *name;
    int score;
    struct list_head list;
}linknode, *linklist;

//初始化内核链表
linklist init_list(){
    linklist head = malloc(sizeof(linknode));
    if(head != NULL)
        INIT_LIST_HEAD(&head->list);
    return head;
}

linklist new_node(char *name, int score){
    linklist new = malloc(sizeof(linknode));
    if(new != NULL){
        new->name = strdup(name);
        new->score = score;
        INIT_LIST_HEAD(&new->list);
    }
    return new;
}

void show_list(linklist head){
    struct list_head *pos;
    list_for_each(pos, &head->list){
        linklist data = list_entry(pos, linknode, list);
        printf("%s %d\n", data->name, data->score);
    }
}

int main(int argc, char const *argv[])
{
    FILE *fp = fopen("record.txt", "r");
    linklist head = init_list();
    char temp_name[100];
    int temp_score;
    while(1){
        if(fscanf(fp, "%s %d", temp_name, &temp_score) == EOF)break;
        list_add_tail(&new_node(temp_name, temp_score)->list, &head->list);
    }
    fclose(fp);
    show_list(head);
    return 0;
}
